package main

import (
	"github.com/gin-gonic/gin"
	"gomicrodemo/gin-api-gateway/client"
	"gomicrodemo/gin-api-gateway/handler"
	"gomicrodemo/gin-api-gateway/middlewarre"
)

func main() {
	r := gin.Default()
	api := r.Group("/v1")

	//获取对应的Rand服务的客户端
	userClient := client.GetUserClient()
	randClient := client.GetRandClient()

	//获取Rand服务端对应的处理程序的调用对象 : func GetAPIHandler(service rand.RandService) *APIHandler{}
	apiHandler := handler.GetAPIHandler(randClient, userClient)

	//获取rand服务的客户端
	api.POST("rand", middlewarre.AuthMiddleware(), apiHandler.Rand_POST)
	api.GET("rand", apiHandler.Rand_GET)

	//获取user服务的客户端,
	api.POST("registry", apiHandler.UserRegistry)
	api.POST("login", apiHandler.UserLogin)

	if err := r.Run(); err != nil {
		panic(err)
	}
}
